$(document).ready(function(){
	// 导入模块
	const api = require("../modules/api.js");

	let list = [];
	// 获取地址
	api.address_myList().then(data=>{
		console.log(data);
		if(data.code == "0"){
			list = data.result.list || [];
			console.log(list);
		};
	});

	// 选择地址
	$(".address-section").click(function(){
		let id = $(this).data().id;
		$(".address-section").find(".address-icon").attr({"src": "/img/h5/select_icon.png"});
		$(this).find(".address-icon").attr({"src": "/img/h5/selected_icon.png"});
		
		let address = {};
		list.map(item=>{
			if(item.id == id){
				address = item;
			}
		});
		sessionStorage.setItem("address", JSON.stringify(address));

		setTimeout(()=>{
			window.location.href = "/h5/order_confirm";
		}, 300);
	});
});